#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

void solve()
{
	int n,m;
	cin>>n>>m;
	int x,y,a,b;
	cin>>x>>y>>a>>b;
	int ans=0;
	int res=0;
	if(x-1>=1) ans++;
	if(x+1<=n) ans++;
	if(y-1>=1) ans++;
	if(y+1<=m) ans++;
	
	x=a;
	y=b;
	if(x-1>=1) res++;
	if(x+1<=n) res++;
	if(y-1>=1) res++;
	if(y+1<=m) res++;
	cout<<min(res,ans)<<endl;
}
int main()
{
	IOS;
	int T=1;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

